package com.lk.lkappearance.service.impl;

import com.lk.lkappearance.common.AbstractBaseService;
import com.lk.lkappearance.mapper.RoleMapper;
import com.lk.lkappearance.model.Role;
import com.lk.lkappearance.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class RoleServiceImpl extends AbstractBaseService implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    /**
     * @param role
     * @return
     */
    @Override
    public Map<String, Object> add(Role role) {
        try {
            roleMapper.insertSelective(role);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     * @param role
     * @return
     */
    @Override
    public Map<String, Object> modify(Role role) {
        try {
            role.setUpdateTime(new Date());
            roleMapper.updateByPrimaryKeySelective(role);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     * @param roleId
     * @return
     */
    @Override
    public Map<String, Object> delete(String roleId) {
        try {
            roleMapper.deleteByPrimaryKey(roleId);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     * 得到权限列表
     *
     * @param role
     * @return
     */
    @Override
    public Map<String, Object> getList(Role role) {
        Map<Object, Object> result = new HashMap<>();
        try {
            List<Role> list = roleMapper.getList(role);
            result.put("list",list);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().setData(result).getResult();
    }
}
